#!/usr/bin/env python
# coding=utf-8
# 15/4/5 14:04 zhuxuehuang

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mydj.settings")
import django
django.setup()

from app.models import Book, Author

# b1 = Book.objects.create(title='book one')

# a1 = Author()
# a1.first_name = 'zhu'
# a1.last_name = 'xuehuang'
# a1.email = 'itsky365@163.com'
# a1.save()

# a1 = Author()
# a1.first_name = 'zhang'
# a1.last_name = 'nannan'
# a1.email = '270667789@163.com'
# a1.save()

# a1 = Author.objects.get(pk=1)
#
# b1 = Book.objects.get(pk=2)
# b1.authors.add(a1)
# b1.save()

# b2 = Book.objects.get(pk=1)
# print(b2)
# print(b2.authors.all())
# print(b2.authors.filter(first_name='zhu'))
#
# a = Author.objects.get(pk=1)
# # print(a.book_set.create(title='book 4'))
# print(a.book_set.all())
# a.book_set.exists()
#
# print(a.book_set.all())


# a3, r = Author.objects.get_or_create(first_name='zhu2', last_name='wenzhuo')
# print(a3)
# print(r)
# a3.email = 'zhuwenzhuo@qq.com'
# a3.save()

a4 = Author.objects.filter(book__title__contains='book 3')
print(a4)

# print(a4.book_set.all())